package com.tgy.myplus.基础学习.Thread.Synchronized;

/**
 * @author 送你一块二向箔
 * @date 2021/11/08 17:29
 */

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 测试JUC安全类型集合
 */
public class TestJUC {
    public static void main(String[] args) throws InterruptedException {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                list.add(Thread.currentThread().getName());
            }).start();
        }

        //保证线程执行完毕
        Thread.sleep(1000);
        System.out.println(list.size());
    }
}
